/**
 * 变更分类公共JS
 */

import ChangeCategoryDialog from "@/views/modules/share/ChangeCategoryDialog";
import {Util,I18Parse,CommonLang} from "@lowcode/jpaas-common-lib"
import ChangeCategoryLang from '../../../locales/lang/impl/assets/ChangeCategoryLang.js'


let lang = ChangeCategoryLang.changeCategory;
let i18n=function (langKey,text) {
    return I18Parse.getI18Val(lang,langKey, text)
}

export default {
    data() {
        return {

        }
    },
    methods:{
        openCategoryDialog(){
            if(!this.categoryConfig){
                this.$message.warning(i18n('notConfig','未定义变更分类配置!'));
                return;
            }
            if(!this.categoryConfig.Api){
                this.$message.warning(i18n('notApi','未定义变更分类Api!'));
                return;
            }
            let self = this;
            let conf = {
                curVm: self,
                component: ChangeCategoryDialog,
                title: this.$ti18('rxList.changeCategory','切换分类'),
                widthHeight: ['400px', '600px'],
                data: {
                    catKey:this.categoryConfig.catKey
                },
                zIndex: 9999,
            };
            Util.open(conf, function (action, categoryId) {
                if (action != 'ok' || !categoryId) return;
                self.categoryConfig.Api.changeCategory(self.selectedRowKeys.join(','), categoryId).then(res=>{
                    if(res && res.success){
                        self.$refs[self.categoryConfig.gridRef].loadData()
                    }
                });
            });
        },
        /**
         * 选择分类.
         * @param catKey
         * @param callback
         */
        selectCategory(catKey,callback){
            let self = this;
            let conf = {
                curVm: self,
                component: ChangeCategoryDialog,
                title: "选择分类",
                widthHeight: ['400px', '600px'],
                data: {
                    catKey:catKey
                },
                zIndex: 9999,
            };
            Util.open(conf, function (action, categoryId) {
                if (action != 'ok' || !categoryId || !callback) return;
                callback(categoryId);
            });
        }
    }
}
